import org.dom4j.DocumentException;

import java.io.File;
import java.util.*;

public class Main {
    // xml文件夹的位置
    public static String folder = "E:\\live stream\\xml analysis";
    // 需要匹配的弹幕正则表达式
    public static String regex = "[\\w\\u4e00-\\u9fa5]*异客[\\w\\u4e00-\\u9fa5]*";

    public static void main(String[] args) {
        List<BilibiliUser> users = new ArrayList<>();
        Map<String, Integer> userMap = new HashMap<>();
        // * read xml files
        try {
            File[] files = new File(folder).listFiles();
            for (File file: files) {
                Utils.processXml(file, users, userMap, regex);
            }
        } catch (DocumentException e) {
            e.printStackTrace();
        }
        if(users != null) {
            // * analysis data
            int total = 0;
            int big = 0, middle = 0, small = 0;
            for(BilibiliUser user : users) {
                total += user.barrageNum;
                if(user.barrageNum >= 15)
                    big++;
                else if(user.barrageNum >= 5)
                    middle++;
                else small++;
            }
            System.out.println("共有" + users.size() + "位用户刷了" + total + "条异客");
            System.out.println("其中" + big + "人发了15条以上");
            System.out.println("其中" + middle + "人发了5条以上15条以下");
            System.out.println("其中" + small + "人发了5条以下");

            Collections.sort(users, new Comparator<BilibiliUser>() {
                @Override
                public int compare(BilibiliUser o1, BilibiliUser o2) {
                    return o2.barrageNum - o1.barrageNum;
                }
            });

            for (BilibiliUser user: users) {
                if(user.barrageNum > 0) {
                    System.out.println(user);
                }
            }
        }
    }
}
